package com.southpark.system.view.toolTips
{
	import com.southpark.system.interfaces.managers.IToolTipManager;
	
	import flash.geom.Point;
	
	import mx.core.FlexGlobals;
	import mx.core.UIComponent;
	
	
	public class ToolTipTarget
	{
		[Bindable]public var isMenuMode:Boolean;
		public var origin:UIComponent;
		
		private var toolTipInterface:Class
		private var toolTipManager:IToolTipManager;
		private var trapMouse:Boolean;
		
		
		public function ToolTipTarget(toolTipManager:IToolTipManager,origin:UIComponent,toolTipInterface:Class,trapMouse:Boolean=true)
		{
			this.toolTipManager = toolTipManager;
			this.origin = origin;
			this.toolTipInterface =  toolTipInterface;
			this.trapMouse = trapMouse;
		}
		
		public function onRollOver():void
		{
			if (!toolTipManager.toolTipUI || toolTipManager.toolTipUI.toolTipTarget != this)
			{
				isMenuMode = true;
			};
		}
		
		public function onRollOut():void
		{
			isMenuMode = false;
			
			if (toolTipManager.toolTipUI && !toolTipManager.toolTipUI.isMouseTrapped())
			{
				toolTipManager.hideToolTip();
			};
		}
		
		public function showToolTip(data:Object):void
		{
			var point:Point = new Point(origin.x,origin.y);
			point = origin.contentToGlobal(point);
			
			toolTipManager.showToolTip(this,toolTipInterface,point,data);
			isMenuMode = false;
		}
		
		public function isMouseTrapped():Boolean
		{
			if (trapMouse) 
			{
				return origin.hitTestPoint(FlexGlobals.topLevelApplication.mouseX,FlexGlobals.topLevelApplication.mouseY);
			};
			
			return false;
		}
		
	}
}